home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kpixmapregionselectorwidget.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  4.9 KB  |  171 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 2004 Antonio Larrosa <larrosa@kde.org
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __KPIXMAPREGIONSELECTORWIDGET_H__
  21. #define __KPIXMAPREGIONSELECTORWIDGET_H__
  22. #include <qvbox.h>
  23. #include <qpixmap.h>
  24. #include <qrect.h>
  25. #include <qlabel.h>
  26. #include <kimageeffect.h>
  27.  
  28. class KPopupMenu;
  29.  
  30. #include <kdelibs_export.h>
  31.  
  32. /**
  33.  * KPixmapRegionSelectorWidget is a widget that shows a picture and provides the
  34.  * user with a friendly way to select a rectangular subregion of the pixmap.
  35.  *
  36.  * NOTE: There are two copies of this .h and the .cpp file, with subtle differences.
  37.  * One copy is in kdelibs/kdeui, and the other copy is in kdepim/libkdepim
  38.  * This is because kdepim has to remain backwards compatible.  Any changes
  39.  * to either file should be made to the other.
  40.  *
  41.  * @author Antonio Larrosa <larrosa@kde.org>
  42.  * @since 3.4
  43.  */
  44. class KDEUI_EXPORT KPixmapRegionSelectorWidget : public QWidget
  45. {
  46.    Q_OBJECT
  47. public:
  48.    /**
  49.     * Constructor for a KPixmapRegionSelectorWidget.
  50.     */
  51.    KPixmapRegionSelectorWidget( QWidget *parent = 0L, const char *name=0L);
  52.  
  53.    /**
  54.     * Destructor for a KPixmapRegionSelectorWidget
  55.     */
  56.    ~KPixmapRegionSelectorWidget();
  57.  
  58.    /**
  59.     * Sets the pixmap which will be shown for the user to select a region from.
  60.     * @param pixmap The pixmap.  Must be non-null.
  61.     * 
  62.     */
  63.    void setPixmap( const QPixmap &pixmap );
  64.  
  65.    /**
  66.     * @return the original whole pixmap that we're using in this widget as the
  67.     * pixmap the user is selecting a region from.
  68.     */
  69.    QPixmap pixmap() const { return m_unzoomedPixmap; }
  70.  
  71.    /**
  72.     * Sets the selected region to be @p rect (in zoomed pixmap coordinates)
  73.     */
  74.    void setSelectedRegion(const QRect &rect);
  75.  
  76.    /**
  77.     * Returns the selected region ( in zoomed pixmap coordinates )
  78.     */
  79.    QRect selectedRegion() const;
  80.  
  81.    /**
  82.     * Returns the selected region ( in unzoomed, original pixmap coordinates )
  83.     */
  84.    QRect unzoomedSelectedRegion() const;
  85.  
  86.    /**
  87.     * Resets the selection to use the whole image
  88.     */
  89.    void resetSelection();
  90.  
  91.    /**
  92.     * @returns a QImage object with just the region the user selected from the
  93.     * image
  94.     */
  95.    QImage selectedImage() const;
  96.  
  97.    /**
  98.     * Sets the aspect ration that the selected subimage should have. The way to
  99.     * select it, is specifying an example valid @p width and @p height.
  100.     * @see setFreeSelectionAspectRatio()
  101.     */
  102.    void setSelectionAspectRatio(int width, int height);
  103.  
  104.    /**
  105.     * Allows the user to do a selection which has any aspect ratio. This is
  106.     * the default.
  107.     * @see setSelectionAspectRatio()
  108.     */
  109.    void setFreeSelectionAspectRatio();
  110.  
  111.    /**
  112.     * Sets the maximum size for the widget. If the image is larger than this
  113.     * (either horizontally or vertically), it's scaled to adjust to the maximum
  114.     * size (preserving the aspect ratio)
  115.     */
  116.    void setMaximumWidgetSize( int width, int height );
  117.  
  118.    /**
  119.     * Rotates the image as specified by the @p direction parameter, also tries
  120.     * to rotate the selected region so that it doesn't change, as long as the
  121.     * forced aspect ratio setting is respected, in other case, the selected region
  122.     * is resetted.
  123.     */
  124.    void rotate(KImageEffect::RotateDirection direction);
  125.  
  126. public slots:
  127.    /**
  128.     * Rotates the current image 90┬║ clockwise
  129.     */
  130.    void rotateClockwise();
  131.    /**
  132.     * Rotates the current image 90┬║ counterclockwise
  133.     */
  134.    void rotateCounterclockwise();
  135.  
  136. protected:
  137.    /**
  138.     * Creates a KPopupMenu with the menu that appears when clicking with the right button on the label
  139.     */
  140.    virtual KPopupMenu *createPopupMenu();
  141.  
  142. private:
  143.    bool eventFilter(QObject *obj, QEvent *ev);
  144.  
  145.    /**
  146.     * Recalculates the pixmap that is shown based on the current selected area,
  147.     * the original image, etc. 
  148.     */
  149.    void updatePixmap();
  150.  
  151.    QRect calcSelectionRectangle( const QPoint &startPoint, const QPoint & endPoint );
  152.  
  153.    enum CursorState { None=0, Resizing, Moving };
  154.    CursorState m_state;
  155.  
  156.    QPixmap m_unzoomedPixmap;
  157.    QPixmap m_originalPixmap;
  158.    QPixmap m_linedPixmap;
  159.    QRect   m_selectedRegion;
  160.    QLabel *m_label;
  161.  
  162.    QPoint m_tempFirstClick;
  163.    double m_forcedAspectRatio;
  164.  
  165.    int m_maxWidth, m_maxHeight;
  166.    double m_zoomFactor;
  167. };
  168.  
  169. #endif
  170.  
  171.